home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODUtil / Sources / FWRect.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  21.2 KB  |  704 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWRect.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWRECT_H
  13. #include "FWRect.h"
  14. #endif
  15.  
  16. // ----- Foundation Includes -----
  17.  
  18. #ifndef FWFXMATH_H
  19. #include "FWFxMath.h"
  20. #endif
  21.  
  22. #ifndef FWSTREAM_H
  23. #include "FWStream.h"
  24. #endif
  25.  
  26. // ----- OpenDoc Includes -----
  27.  
  28. #ifndef _ODTYPES_
  29. #include <ODTypes.h>
  30. #endif
  31.  
  32. //========================================================================================
  33. //    RunTime Info
  34. //========================================================================================
  35.  
  36. #if FW_LIB_EXPORT_PRAGMAS
  37. #pragma lib_export on
  38. #endif
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment fwodutil
  42. #endif
  43.  
  44. //========================================================================================
  45. //    struct FW_SPlatformRect
  46. //========================================================================================
  47.  
  48. //----------------------------------------------------------------------------------------
  49. //    FW_SPlatformRect::FW_SPlatformRect
  50. //----------------------------------------------------------------------------------------
  51.  
  52. FW_SPlatformRect::FW_SPlatformRect(const FW_CRect& rect)
  53. {
  54.     left    = rect.left.AsInt();
  55.     top        = rect.top.AsInt();
  56.     right    = rect.right.AsInt();
  57.     bottom    = rect.bottom.AsInt();
  58. }
  59.  
  60. //----------------------------------------------------------------------------------------
  61. //    FW_SPlatformRect::operator =
  62. //----------------------------------------------------------------------------------------
  63.  
  64. FW_SPlatformRect& FW_SPlatformRect::operator =(const FW_CRect& rect)
  65. {
  66.     left    = rect.left.AsInt();
  67.     top        = rect.top.AsInt();
  68.     right    = rect.right.AsInt();
  69.     bottom    = rect.bottom.AsInt();
  70.     
  71.     return *this;
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //    FW_SPlatformRect::operator==
  76. //----------------------------------------------------------------------------------------
  77.  
  78. FW_Boolean FW_SPlatformRect::operator==(const FW_SPlatformRect& rect) const
  79. {
  80.     return
  81.         left    ==    rect.left    &&
  82.         top        ==    rect.top    &&
  83.         right    ==    rect.right    &&
  84.         bottom    ==    rect.bottom;
  85. }
  86.  
  87. //----------------------------------------------------------------------------------------
  88. //    FW_SPlatformRect::operator!=
  89. //----------------------------------------------------------------------------------------
  90.  
  91. FW_Boolean FW_SPlatformRect::operator!=(const FW_SPlatformRect& rect) const
  92. {
  93.     return
  94.         left    !=    rect.left    ||
  95.         top        !=    rect.top    ||
  96.         right    !=    rect.right    ||
  97.         bottom    !=    rect.bottom;
  98. }
  99.  
  100. //========================================================================================
  101. //    class FW_CRect
  102. //========================================================================================
  103.  
  104. //----------------------------------------------------------------------------------------
  105. //    FW_CRect::FW_CRect
  106. //----------------------------------------------------------------------------------------
  107.  
  108. FW_CRect::FW_CRect() :
  109.     left    (FW_IntToFixed(0)),
  110.     top        (FW_IntToFixed(0)),
  111.     right    (FW_IntToFixed(0)),
  112.     bottom    (FW_IntToFixed(0))
  113. {
  114. }
  115.         
  116. //----------------------------------------------------------------------------------------
  117. //    FW_CRect::FW_CRect
  118. //----------------------------------------------------------------------------------------
  119.  
  120. FW_CRect::FW_CRect(FW_CFixed l, FW_CFixed t, FW_CFixed r, FW_CFixed b) :
  121.     left    (l),
  122.     top        (t),
  123.     right    (r),
  124.     bottom    (b)
  125. {
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    FW_CRect::FW_CRect
  130. //----------------------------------------------------------------------------------------
  131.  
  132. FW_CRect::FW_CRect(const FW_CPoint &topLeft, const FW_CPoint &botRight)
  133. {
  134.     left = topLeft.x;        right = botRight.x;
  135.     top = topLeft.y;        bottom = botRight.y;
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    FW_CRect::FW_CRect
  140. //----------------------------------------------------------------------------------------
  141.  
  142. FW_CRect::FW_CRect(const FW_CPoint &startPoint, const FW_CPoint &endPoint, FW_CFixed penSize)
  143. {
  144.     left = startPoint.x;                
  145.     right = endPoint.x;
  146.     top  = startPoint.y;                
  147.     bottom= endPoint.y;
  148.     
  149.     Sort();
  150.     
  151.     right -= penSize;
  152.     bottom -= penSize;
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    FW_CRect::FW_CRect
  157. //----------------------------------------------------------------------------------------
  158.  
  159. FW_CRect::FW_CRect(const FW_CPoint &topLeft, FW_CFixed width, FW_CFixed height )
  160. {
  161.     left = topLeft.x;        right = left + width;
  162.     top  = topLeft.y;        bottom= top + height;
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. //    FW_CRect::FW_CRect
  167. //----------------------------------------------------------------------------------------
  168.  
  169. FW_CRect::FW_CRect(const ODRect& rect) :
  170.     left    (FW_ODFixedToFixed(rect.left)),
  171.     top        (FW_ODFixedToFixed(rect.top)),
  172.     right    (FW_ODFixedToFixed(rect.right)),
  173.     bottom    (FW_ODFixedToFixed(rect.bottom))
  174. {
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. //    FW_CRect::FW_CPoint
  179. //----------------------------------------------------------------------------------------
  180.  
  181. FW_CRect::FW_CRect(const FW_CReadableStream& stream)
  182. {
  183.     stream.Read(this, sizeof(ODRect));
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    FW_CRect:: operator=
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_CRect& FW_CRect:: operator=(const ODRect& odRect)
  191. {
  192.     left = FW_ODFixedToFixed(odRect.left);    right = FW_ODFixedToFixed(odRect.right);
  193.     top  = FW_ODFixedToFixed(odRect.top);    bottom= FW_ODFixedToFixed(odRect.bottom);
  194.  
  195.     return *this;
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    FW_CRect::FW_CRect
  200. //----------------------------------------------------------------------------------------
  201.  
  202. FW_CRect::FW_CRect(const FW_PlatformRect& plfmRect) :
  203.     left     (FW_IntToFixed(plfmRect.left)),
  204.     top      (FW_IntToFixed(plfmRect.top)),
  205.     right    (FW_IntToFixed(plfmRect.right)),
  206.     bottom    (FW_IntToFixed(plfmRect.bottom))
  207. {
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    FW_CRect::FW_CRect
  212. //----------------------------------------------------------------------------------------
  213.  
  214. FW_CRect::FW_CRect(const FW_CRect& rect) :
  215.     left    (rect.left),
  216.     top        (rect.top),
  217.     right    (rect.right),
  218.     bottom    (rect.bottom)
  219. {
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    FW_CRect::operator=
  224. //----------------------------------------------------------------------------------------
  225.  
  226. FW_CRect& FW_CRect::operator=(const FW_PlatformRect& plfmRect)
  227. {
  228.     left = FW_IntToFixed(plfmRect.left);    right = FW_IntToFixed(plfmRect.right);
  229.     top  = FW_IntToFixed(plfmRect.top);        bottom= FW_IntToFixed(plfmRect.bottom);
  230.  
  231.     return *this;
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    FW_CRect:: operator=
  236. //----------------------------------------------------------------------------------------
  237.  
  238. FW_CRect& FW_CRect:: operator=(const FW_CRect& rect)
  239. {
  240.     left = rect.left;        right = rect.right;
  241.     top  = rect.top;        bottom= rect.bottom;
  242.  
  243.     return *this;
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_CRect::Set
  248. //----------------------------------------------------------------------------------------
  249.  
  250. void FW_CRect::Set(FW_CFixed l, FW_CFixed t, FW_CFixed r, FW_CFixed b)
  251. {
  252.     left = l;                right = r;
  253.     top  = t;                bottom= b;
  254. }
  255.  
  256. //----------------------------------------------------------------------------------------
  257. //    FW_CRect::Set
  258. //----------------------------------------------------------------------------------------
  259.  
  260. void FW_CRect::Set(const FW_CPoint &topLeft, FW_CFixed width, FW_CFixed height)
  261. {
  262.     left = topLeft.x;                right = left+width;
  263.     top  = topLeft.y;                bottom= top +height;
  264. }
  265.  
  266. //----------------------------------------------------------------------------------------
  267. //     FW_CRect::SetInt
  268. //----------------------------------------------------------------------------------------
  269.  
  270. void FW_CRect::SetInt(short l, short t, short r, short b)
  271. {
  272.     left = FW_IntToFixed(l);            right = FW_IntToFixed(r);
  273.     top  = FW_IntToFixed(t);            bottom= FW_IntToFixed(b);
  274. }
  275.  
  276. //----------------------------------------------------------------------------------------
  277. //    FW_CRect::Offset
  278. //----------------------------------------------------------------------------------------
  279.  
  280. void FW_CRect::Offset(FW_CFixed x, FW_CFixed y)
  281. {
  282.     left += x;                right += x;
  283.     top  += y;                bottom+= y;
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. //    FW_CRect::Offset
  288. //----------------------------------------------------------------------------------------
  289.  
  290. void FW_CRect::Offset(const FW_CPoint &pt)
  291. {
  292.     left += pt.x;            right += pt.x;
  293.     top  += pt.y;            bottom+= pt.y;
  294. }
  295.  
  296. //----------------------------------------------------------------------------------------
  297. //    FW_CRect::Place
  298. //----------------------------------------------------------------------------------------
  299.  
  300. void FW_CRect::Place(FW_CFixed x, FW_CFixed y)
  301. {
  302.     right += x - left;
  303.     left = x;
  304.     bottom += y - top;
  305.     top = y;
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    FW_CRect::Place
  310. //----------------------------------------------------------------------------------------
  311.  
  312. void FW_CRect::Place(const FW_CPoint &pt)
  313. {
  314.     right += pt.x - left;
  315.     left = pt.x;
  316.     bottom += pt.y - top;
  317.     top = pt.y;
  318. }
  319.  
  320. //----------------------------------------------------------------------------------------
  321. //    FW_CRect::PlaceInCenter
  322. //----------------------------------------------------------------------------------------
  323.  
  324. void FW_CRect::PlaceInCenter(const FW_CRect& otherRect)
  325. {
  326.     FW_CFixed newTop = (otherRect.bottom + otherRect.top - bottom + top).Half();
  327.     bottom = newTop + bottom - top;
  328.     top = newTop;
  329.  
  330.     FW_CFixed newLeft = (otherRect.right + otherRect.left - right + left).Half();
  331.     right = newLeft + right - left;
  332.     left = newLeft;        
  333. }
  334.  
  335. //----------------------------------------------------------------------------------------
  336. //    FW_CRect::Inset
  337. //----------------------------------------------------------------------------------------
  338.  
  339. void FW_CRect::Inset(FW_CFixed x, FW_CFixed y )
  340. {
  341.     left += x;
  342.     right -= x;
  343.     top += y;
  344.     bottom -= y;
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. //    FW_CRect::Clear
  349. //----------------------------------------------------------------------------------------
  350.  
  351. void FW_CRect::Clear( )
  352. {
  353.     left = right = top = bottom = FW_IntToFixed(0);
  354. }
  355.  
  356. //----------------------------------------------------------------------------------------
  357. //    operator|= FW_CPoint
  358. //----------------------------------------------------------------------------------------
  359.  
  360. void FW_CRect:: operator|= (const FW_CPoint &pt)
  361. {
  362.     left = FW_Minimum(left,pt.x);
  363.     right= FW_Maximum(right,pt.x);
  364.     top  = FW_Minimum(top,pt.y);
  365.     bottom=FW_Maximum(bottom,pt.y);
  366. }
  367.  
  368. //----------------------------------------------------------------------------------------
  369. //    FW_CRect::AsPlatformRect
  370. //----------------------------------------------------------------------------------------
  371.  
  372. void FW_CRect::AsPlatformRect(FW_PlatformRect &plfmRect) const
  373. {
  374.     plfmRect.left        = left.AsInt();
  375.     plfmRect.top        = top.AsInt();
  376.     plfmRect.right        = right.AsInt();
  377.     plfmRect.bottom        = bottom.AsInt();
  378. }
  379.  
  380. //----------------------------------------------------------------------------------------
  381. //    FW_CRect::IsEmpty
  382. //----------------------------------------------------------------------------------------
  383.  
  384. FW_Boolean FW_CRect::IsEmpty() const
  385. {
  386.     return right<=left || bottom<=top;
  387. }
  388.  
  389. //----------------------------------------------------------------------------------------
  390. //    FW_CRect::Contains
  391. //----------------------------------------------------------------------------------------
  392.  
  393. FW_Boolean FW_CRect::Contains(const FW_CPoint &pt) const
  394. {
  395.     return left<=pt.x && pt.x<right
  396.         && top <=pt.y && pt.y<bottom;
  397. }
  398.  
  399. //----------------------------------------------------------------------------------------
  400. //    FW_CRect::Contains
  401. //----------------------------------------------------------------------------------------
  402.  
  403. FW_Boolean FW_CRect::Contains( const FW_CRect &r) const
  404. {
  405.     return left<=r.left && r.right<=right
  406.         && top <=r.top  && r.bottom<=bottom;
  407. }
  408.  
  409. //----------------------------------------------------------------------------------------
  410. //    FW_CRect::operator==
  411. //----------------------------------------------------------------------------------------
  412.  
  413. FW_Boolean FW_CRect::operator==(const FW_CRect &r) const
  414. {
  415.     return (left == r.left && top == r.top  && right == r.right  && bottom == r.bottom);
  416. }
  417.  
  418. //----------------------------------------------------------------------------------------
  419. //    FW_CRect::IsIntersecting
  420. //----------------------------------------------------------------------------------------
  421.  
  422. FW_Boolean FW_CRect::IsIntersecting(const FW_CRect &r) const
  423. {
  424.     return FW_Maximum(left,r.left) < FW_Minimum(right,r.right)
  425.         && FW_Maximum(top,r.top) < FW_Minimum(bottom,r.bottom);
  426. }
  427.  
  428. //----------------------------------------------------------------------------------------
  429. //    FW_CRect::Intersection
  430. //----------------------------------------------------------------------------------------
  431.  
  432. void FW_CRect::Intersection(const FW_CRect &r)
  433. {
  434.     left = FW_Maximum(left, r.left);
  435.     top = FW_Maximum(top, r.top);
  436.     right = FW_Minimum(right, r.right);
  437.     bottom = FW_Minimum(bottom, r.bottom);
  438.     
  439.     if (IsEmpty())
  440.         SetInt(0,0,0,0);
  441. }
  442.  
  443. //----------------------------------------------------------------------------------------
  444. //    FW_CRect::Intersection
  445. //----------------------------------------------------------------------------------------
  446.  
  447. void FW_CRect::Intersection(const FW_CRect &r1, const FW_CRect &r2)
  448. {
  449.     left = FW_Maximum(r1.left, r2.left);
  450.     top = FW_Maximum(r1.top, r2.top);
  451.     right = FW_Minimum(r1.right, r2.right);
  452.     bottom = FW_Minimum(r1.bottom, r2.bottom);
  453.     
  454.     if (IsEmpty())
  455.         SetInt(0,0,0,0);
  456. }
  457.  
  458. //----------------------------------------------------------------------------------------
  459. //    FW_CRect::Union
  460. //----------------------------------------------------------------------------------------
  461.  
  462. void FW_CRect::Union(const FW_CRect &rect)
  463. {
  464.     left = FW_Minimum(left, rect.left);
  465.     right= FW_Maximum(right, rect.right);
  466.     top  = FW_Minimum(top, rect.top);
  467.     bottom=FW_Maximum(bottom, rect.bottom);
  468.     
  469.     if (IsEmpty())
  470.         SetInt(0,0,0,0);
  471. }
  472.  
  473. //----------------------------------------------------------------------------------------
  474. //    FW_CRect::Union
  475. //----------------------------------------------------------------------------------------
  476.  
  477. void FW_CRect::Union(const FW_CRect &r1, const FW_CRect &r2)
  478. {
  479.     left = FW_Minimum(r1.left, r2.left);
  480.     right= FW_Maximum(r1.right, r2.right);
  481.     top  = FW_Minimum(r1.top, r2.top);
  482.     bottom=FW_Maximum(r1.bottom, r2.bottom);
  483.     
  484.     if (IsEmpty())
  485.         SetInt(0,0,0,0);
  486. }
  487.  
  488. //----------------------------------------------------------------------------------------
  489. //    FW_CRect::Sort
  490. //----------------------------------------------------------------------------------------
  491.  
  492. void FW_CRect::Sort()
  493. {
  494.     if (left > right)
  495.     {
  496.         FW_CFixed temp = left;
  497.         left = right;
  498.         right = temp;
  499.     }
  500.     if (top > bottom)
  501.     {
  502.         FW_CFixed temp = top;
  503.         top = bottom;
  504.         bottom = temp;
  505.     }
  506. }
  507.  
  508. //----------------------------------------------------------------------------------------
  509. //    FW_CRect::Map
  510. //----------------------------------------------------------------------------------------
  511. //     The result may not be sorted. You might have to call Sort.
  512.  
  513. void FW_CRect::Map(const FW_CRect& srcRect, const FW_CRect& dstRect)
  514. {
  515.     FW_CFixed ratio = (right - left) / (srcRect.right - srcRect.left);
  516.     
  517.     left    += ratio * (dstRect.left - srcRect.left);
  518.     right    += ratio * (dstRect.right - srcRect.right);
  519.  
  520.  
  521.     ratio = (bottom - top) / (srcRect.bottom - srcRect.top);
  522.     
  523.     top        += ratio * (dstRect.top - srcRect.top);
  524.     bottom    += ratio * (dstRect.bottom - srcRect.bottom);
  525. }
  526.  
  527. //----------------------------------------------------------------------------------------
  528. //    FW_CRect::Transform
  529. //----------------------------------------------------------------------------------------
  530.  
  531. void FW_CRect::Transform(Environment* ev, ODTransform* transform)
  532. {
  533. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  534.     * (((ODPoint*) this) + 0) =
  535. #endif
  536.     transform->TransformPoint(ev, ((ODPoint*) this) + 0);
  537.     
  538. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  539.     * (((ODPoint*) this) + 1) =
  540. #endif
  541.     transform->TransformPoint(ev, ((ODPoint*) this) + 1);
  542. }
  543.  
  544. //----------------------------------------------------------------------------------------
  545. //    FW_CRect::InverseTransform
  546. //----------------------------------------------------------------------------------------
  547.  
  548. void FW_CRect::InverseTransform(Environment* ev, ODTransform* transform)
  549. {
  550. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  551.     * (((ODPoint*) this) + 0) =
  552. #endif
  553.     transform->InvertPoint(ev, ((ODPoint*) this) + 0);
  554.  
  555. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  556.     * (((ODPoint*) this) + 1) =
  557. #endif
  558.     transform->InvertPoint(ev, ((ODPoint*) this) + 1);
  559. }
  560.  
  561. //----------------------------------------------------------------------------------------
  562. //    FW_CRect::TransformCopy
  563. //----------------------------------------------------------------------------------------
  564.  
  565. FW_CRect FW_CRect::TransformCopy(Environment* ev, ODTransform* transform) const
  566. {
  567.     FW_CRect rect(*this);
  568.  
  569. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  570.     * (((ODPoint*) &rect) + 0) =
  571. #endif
  572.     transform->TransformPoint(ev, ((ODPoint*) &rect) + 0);
  573.  
  574. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  575.     * (((ODPoint*) &rect) + 1) =
  576. #endif
  577.     transform->TransformPoint(ev, ((ODPoint*) &rect) + 1);
  578.     
  579.     return rect;
  580. }
  581.  
  582. //----------------------------------------------------------------------------------------
  583. //    FW_CRect::InverseTransformCopy
  584. //----------------------------------------------------------------------------------------
  585.  
  586. FW_CRect FW_CRect::InverseTransformCopy(Environment* ev, ODTransform* transform) const
  587. {
  588.     FW_CRect rect(*this);
  589.  
  590. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  591.     * (((ODPoint*) &rect) + 0) =
  592. #endif
  593.     transform->InvertPoint(ev, ((ODPoint*) &rect) + 0);
  594.  
  595. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  596.     * (((ODPoint*) &rect) + 1) =
  597. #endif
  598.     transform->InvertPoint(ev, ((ODPoint*) &rect) + 1);
  599.     
  600.     return rect;
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. //    FW_CRect::operator[]
  605. //----------------------------------------------------------------------------------------
  606.  
  607. FW_CPoint& FW_CRect::operator[](FW_PointSelector sel)
  608. {
  609.     return (sel == FW_kTopLeft) ? *((FW_CPoint *) &left) : *((FW_CPoint *) &right);
  610. }
  611.  
  612. //----------------------------------------------------------------------------------------
  613. //    FW_CRect::operator[]
  614. //----------------------------------------------------------------------------------------
  615.  
  616. const FW_CPoint& FW_CRect::operator[](FW_PointSelector sel) const
  617. {
  618.     return (sel == FW_kTopLeft) ? *((FW_CPoint *) &left) : *((FW_CPoint *) &right);
  619. }
  620.  
  621. //----------------------------------------------------------------------------------------
  622. //    FW_CRect::Size
  623. //----------------------------------------------------------------------------------------
  624.  
  625. FW_CPoint FW_CRect::Size() const
  626. {
  627.     return FW_CPoint(right - left, bottom - top);
  628. }
  629.  
  630. //----------------------------------------------------------------------------------------
  631. //    FW_CRect::operator+=
  632. //----------------------------------------------------------------------------------------
  633.  
  634. FW_CRect& FW_CRect::operator+=(const FW_CPoint& pt)
  635. {
  636.     left    +=    pt.x;
  637.     top        +=    pt.y;
  638.     right    +=    pt.x;
  639.     bottom    +=    pt.y;
  640.  
  641.     return *this;
  642. }
  643.  
  644. //----------------------------------------------------------------------------------------
  645. //    FW_CRect::operator+
  646. //----------------------------------------------------------------------------------------
  647.  
  648. FW_CRect FW_CRect::operator+(const FW_CPoint& pt) const
  649. {
  650.     return FW_CRect(
  651.         left    +    pt.x,
  652.         top        +    pt.y,
  653.         right    +    pt.x,
  654.         bottom    +    pt.y);
  655. }
  656.  
  657. //----------------------------------------------------------------------------------------
  658. //    FW_CRect::operator-=
  659. //----------------------------------------------------------------------------------------
  660.  
  661. FW_CRect& FW_CRect::operator-=(const FW_CPoint& pt)
  662. {
  663.     left    -=    pt.x;
  664.     top        -=    pt.y;
  665.     right    -=    pt.x;
  666.     bottom    -=    pt.y;
  667.  
  668.     return *this;
  669. }
  670.  
  671. //----------------------------------------------------------------------------------------
  672. //    FW_CRect::operator-
  673. //----------------------------------------------------------------------------------------
  674.  
  675. FW_CRect FW_CRect::operator-(const FW_CPoint& pt) const
  676. {
  677.     return FW_CRect(
  678.         left    -    pt.x,
  679.         top        -    pt.y,
  680.         right    -    pt.x,
  681.         bottom    -    pt.y);
  682. }
  683.  
  684. //----------------------------------------------------------------------------------------
  685. //    operator<<
  686. //----------------------------------------------------------------------------------------
  687.  
  688. FW_FUNC_ATTR const FW_CWritableStream& operator<<(const FW_CWritableStream& stream, const FW_CRect& rect)
  689. {
  690.     stream.Write(&rect, sizeof(FW_CRect));
  691.     return stream;
  692. }
  693.  
  694. //----------------------------------------------------------------------------------------
  695. //    operator>>
  696. //----------------------------------------------------------------------------------------
  697.  
  698. FW_FUNC_ATTR const FW_CReadableStream& operator>>(const FW_CReadableStream& stream, FW_CRect& rect)
  699. {
  700.     stream.Read(&rect, sizeof(FW_CRect));
  701.     return stream;
  702. }
  703.  
  704.